from itchat.content import *
import requests
import json
import itchat

itchat.auto_login(hotReload = True,enableCmdQR=True)
def tuling(info):
   req = requests.get('http://api.qingyunke.com/api.php?key=free&appid=0&msg='+info)
   content = req.text
   print(content)
   data = json.loads(content)
   answer = data["content"]
   print(answer)
   print(data)
   return answer
def group_id(name):
    df = itchat.search_chatrooms(name=name)
    return df[0]['UserName']
@itchat.msg_register([TEXT,MAP,CARD,NOTE,SHARING])
def text_reply(msg):
    itchat.send('%s' % tuling(msg['Text']),msg['FromUserName'])

@itchat.msg_register([PICTURE, RECORDING, ATTACHMENT, VIDEO])
def download_files(msg):
    msg['Text'](msg['FileName'])
    return '@%s@%s' % ({'Picture': 'img', 'Video': 'vid'}.get(msg['Type'], 'fil'), msg['FileName'])

@itchat.msg_register(TEXT, isGroupChat=True)
def group_text_reply(msg):
  if msg['isAt']: 
    item = group_id(u'想要设置的群的名称')  # 根据自己的需求设置
    if msg['ToUserName'] == item:
        itchat.send(u'%s' % tuling(msg['Text']), item)

itchat.run()